package controllers;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.swing.JOptionPane;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import ocsf.server.ConnectionToClient;
/**
 * this class making the direct connection with DB
 */
public class DBConnection {
	
	
	private static DBConnection instance = null;
	
	String url = "jdbc:mysql://localhost/sgi_system";
    String user = "root";
    String sqlPassword = "root";
    private Connection connection;
    
    
    public DBConnection(){
    	try {
			
			 Class.forName("com.mysql.jdbc.Driver").newInstance();
			}
		
		catch (Exception ex){
		}
		
		
		try {
	         connection  = DriverManager.getConnection("jdbc:mysql://localhost/sgi_system",user,sqlPassword);
	        // System.out.println("SQL connection succeed");
			
			}
		
		catch (SQLException ex)
	 	    {		/* handle any errors*/
	    	   
	            System.out.println("SQLException: " + ex.getMessage());
	            System.out.println("SQLState: " + ex.getSQLState());
	            System.out.println("VendorError: " + ex.getErrorCode());
	         }

    	
    }
    
    public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getSqlPassword() {
		return sqlPassword;
	}

	public void setSqlPassword(String sqlPassword) {
		this.sqlPassword = sqlPassword;
	}

	public static DBConnection getInstance(){
    	if(instance == null)
    		instance = new DBConnection();
    	
    	return instance;
    }
    
	public Connection getDBConnection() throws SQLException{
    	
		
		return DriverManager.getConnection(url, user, sqlPassword);
	}

 }
   


	

